import './detail.css';
import {connect} from 'react-redux';
import {Link} from 'react-router';
import Panel from './../../elements/Panel'
import {URL} from '../../libs/Url';
import Fetch from '../../libs/fetch';
import CONFIG from '../../libs/config';
import BreadcrumbNavigation from './../../components/BreadcrumbNavigation';

import {
    fetch,
    fetch_remove,
    enable_delete_btn,
    selectAllItem,
    selectItem,
} from '../../actions';
import {SUBJECT, PAGE_SUBJECT} from './../../actions/subject'
const Title = React.createClass({
    render(){
        return (
            <h1 className="text-center mtop35">{this.props.name}</h1>
        )
    }
});
const Des = React.createClass({
    render(){
        return (
            <p className="text-center auth-row">
                提供者： {this.props.publisher} |
                时间：{Moment(this.props.intime).format('YYYY-MM-DD HH:MM:ss')}
            </p>
        )
    }
})
const Detail = React.createClass({
    getInitialState(){
        return {};
    },
    componentDidMount(){
        const {dispatch} = this.props;
        Fetch(URL.DAY_NEWS_GET, {
            body: {daytopicid: this.props.params.id}
        })
            .then(res=> {
                console.log(res);
                this.setState({
                    daytopics: res.daytopic
                })
            })
            .catch(e=> {
                console.log(e)
            });
        // dispatch(fetch({
        //     url: SUBJECT.DAY_NEWS_GET,
        //     daytopicid: this.props.params.id
        // }));
        // dispatch(fetch(SUBJECT.NEWS_DETAIL, {newsid: this.props.params.id,url:CONFIG.NEWS_PUSH_CLASS}))
    },
    render(){
        const news = this.state.daytopics || {};
        console.log(news);
        return (
            <div>
                <BreadcrumbNavigation navs={[
                    {url: CONFIG.MENUS_ABSOLUTE.HOME, label: '首页'},
                    {url: CONFIG.MENUS_ABSOLUTE.DAY_NEWS, label: '每日一新'},
                    {label: '正文'},
                ]}></BreadcrumbNavigation>

                <Panel>
                    <div className="panel-body">
                        <Title  {...news}></Title>
                        <Des {...news}/>

                        <div className="blog-img-wide">
                            {
                                news.fileid ? <img src={URL.FUN_UPLOAD_PREVIEW(news.fileid)} alt=""/> : null
                            }
                        </div>
                        <div dangerouslySetInnerHTML={{__html: news.comment}}></div>

                    </div>
                </Panel>
            </div>
        )
    }
})
function select(state) {
    return {
        [SUBJECT.DAY_NEWS_DETAIL]: state.fetchBySubject[SUBJECT.DAY_NEWS_DETAIL],
    }
}
export default connect(select)(Detail)